//
//  ViewController.m
//  MessageForwarding
//
//  Created by 刘博 on 15/4/21.
//  Copyright (c) 2015年 AutoNavi. All rights reserved.
//

#import "ViewController.h"
#import <objc/runtime.h>
#import "TestClassA.h"
#import "TestClassB.h"
#import "TestClassC.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    [self testResolveMethod];
}

- (void)testResolveMethod
{
    //ClassA
    
    TestClassA *classA_1 = [[TestClassA alloc] init];
    
    id reVal_1 = [classA_1 performSelector:@selector(doDynamicAddMethod) withObject:@"inString"];
    
    NSLog(@"----------0----------");
    
    TestClassA *classA_2 = [[TestClassA alloc] init];
    
    if ([classA_2 respondsToSelector:@selector(doDynamicAddMethod)])
    {
        NSLog(@"%@ Can Responds To Selector:doDynamicAddMethod", NSStringFromClass([classA_2 class]));
    }
    
    NSLog(@"----------1----------");
    
    TestClassA *classA_3 = [[TestClassA alloc] init];
    
    if ([classA_3 respondsToSelector:@selector(aTestMethod)])
    {
        NSLog(@"Can Responds To Selector:aTestMethod");
    }
    else
    {
        NSLog(@"Can Not Responds To Selector:aTestMethod");
    }
    
    NSLog(@"----------2----------");
    
    //ClassB
    
    TestClassB *classB = [[TestClassB alloc] init];
    
    id reVal_2 = [classB performSelector:@selector(doDynamicAddMethod) withObject:@"inString"];
    
    NSLog(@"----------3----------");
    
    //ClassC
    
    TestClassC *classC = [[TestClassC alloc] init];
    
//    if ([classC respondsToSelector:@selector(aIMPForForwardInvocation)])
//    {
//        NSLog(@"Can Responds To Selector:aIMPForForwardInvocation");
//    }
    
    NSLog(@"----------4----------");
    
    NSString * reStr = [classC performSelector:@selector(aIMPForForwardInvocation)];
    
    NSLog(@"reStr:%@", reStr);
    
    NSLog(@"----------5----------");
    
    if ([classC respondsToSelector:@selector(aTestMethod)])
    {
        NSLog(@"Can Responds To Selector:aTestMethod");
    }
    else
    {
        NSLog(@"Can Not Responds To Selector:aTestMethod");
    }
    
    NSLog(@"----------6----------");
    
    if ([TestClassC instancesRespondToSelector:@selector(aIMPForForwardInvocation)])
    {
        NSLog(@"%@ Can Responds To Selector:aIMPForForwardInvocation", NSStringFromClass([TestClassC class]));
    }
}

@end
